Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: setOSD support DateAndTime #324

Merged
merged 3 commits into from
Jun 7, 2024
Merged

feat: setOSD support DateAndTime #324

merged 3 commits into from
Jun 7, 2024

Conversation

RotemDoar
Copy link
Contributor

Adding ability to set OSD of type DateAndTime.

The function setOSD from lib/media.js previously only supported the addition of Plain Text, as indicated in the comment at line 1286: "ONVIF can handle custom positions, date/time, text, font sizes, transparency, images, etc. We only support Plain Text."

As part of my work, I encountered the need to configure the OSD of date and time for certain cameras. Upon reviewing the Onvif MediaBinding specifications available at https://www.onvif.org/ver10/media/wsdl/media.wsdl and https://www.onvif.org/ver20/media/wsdl/media.wsdl (both media and media2 versions), I found that in the setOSD function, it is possible to set the Type as DateAndTime for configuring date and time display.

Furthermore, I examined the output of the getOSDs function for my cameras and observed that for the OSD date-time, the property "textString" was of type 'DateAndTime'.
For instance, here is the result of getOSDs for one of my cameras:
[ { '$': { token: 'OSD_DATE_TIME' }, videoSourceConfigurationToken: 'VideoSource_token_1', type: 'Text', position: { type: 'Custom', pos: { y: 0.980000019, x: 0.319999993 } }, textString: { type: 'DateAndTime', dateFormat: 'yyyy/MM/dd', timeFormat: 'HH:mm:ss', fontSize: 16, fontColor: [Object], extension: [Object] } },

For adding the ability to change OSD date and time, I firstly I changed the part of TextString in the method setOSD line 1311 as follows -

<sch:TextString IsPersistentText="false">
<sch:Type>Plain</sch:Type>
<sch:PlainText>${options.plaintext}</sch:PlainText>  

To -

<sch:TextString IsPersistentText="false">
<sch:Type>DateAndTime</sch:Type>
<sch:DateFormat>yyyy/MM/dd</sch:DateFormat>
<sch:TimeFormat>HH:mm:ss</sch:TimeFormat>

Added hard-coded the date and time format.
I checked it with my cameras and it works properly, I succeeded to set date and time OSD.

For supported both Plain and DateAndTime, I added an input to the function - dateFormat and timeFormat as I described here -

@param {string} [options.dateFormat] Date to overlay. Must be used with timeFormat, otherwise plaintext will be used.
@param {string} [options.timeFormat] Time to overlay. Must be used with dateFormat, otherwise plaintext will be used.

and changed the TextString part to be -

<sch:TextString IsPersistentText="false">
    ${
          options.dateFormat && options.timeFormat
            ? 
              `<sch:Type>DateAndTime</sch:Type>
	       <sch:DateFormat>${options.dateFormat}</sch:DateFormat>
	       <sch:TimeFormat>${options.timeFormat}</sch:TimeFormat>`
            : 
                `<sch:Type>Plain</sch:Type>
	         <sch:PlainText>${options.plaintext}</sch:PlainText>`
        } 
</sch:TextString>

Copy link
Owner

@agsh agsh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems good to me, thanks!

@agsh
Copy link
Owner

agsh commented Jun 6, 2024

@RotemDoar please fix the lint problems by running eslint --fix lib/*.js

@RotemDoar
Copy link
Contributor Author

Thank you!
@agsh I fixed the lint issues.
running -
npx eslint --fix lib/*.js

now returns no errors.

@agsh agsh merged commit a3ec9af into agsh:master Jun 7, 2024
3 checks passed
@agsh
Copy link
Owner

agsh commented Jun 7, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants